package design.mode.dispatcher.examine.convert;

import design.mode.dispatcher.examine.factory.NumberLetterMapping;

import java.util.HashMap;
import java.util.Map;

public class NumberLetterConverter {
    private NumberLetterMapping numberLetterMapping;

    public NumberLetterConverter() {
        numberLetterMapping = NumberLetterMapping.getInstance();
    }

    public String convert(int number) {
        StringBuilder builder = new StringBuilder();
        for (Map.Entry<Integer, String> entry : numberLetterMapping.getMapping().entrySet()) {
            Integer key = entry.getKey();
            String value = entry.getValue();
            if (number % key == 0) {
                if (builder.toString().contains(String.valueOf(number))) {
                    builder.append(value);
                }else{
                    builder.append(number).append(value);
                }
            }
        }
        return builder.toString().trim();
    }
}